package com.validate.annotation.impl;




import com.validate.advocatevalidator.ValidatorsResult;
import com.validate.annotation.Null;
import com.validate.annotation.ValidatorsHandler;

import java.lang.reflect.Field;

/**
 * 空判断
 */
public class NullControl implements ValidatorsHandler {

	private ValidatorsResult validatorsResult = new ValidatorsResult();
	private Field field;
	private Null aNull;

	/**
	 * 校验
	 *
	 * @param var1
	 * @return
	 */
	@Override
	public boolean validate(Object var1) {
		if (var1 == null) {
			return true;
		}
		return false;
	}

	/**
	 * 字段
	 *
	 * @param var1
	 */
	@Override
	public void field(Field var1) {
		this.field = var1;
		this.aNull = field.getAnnotation(Null.class);
	}

	/**
	 * 结果
	 *
	 * @return false 失败 true 成功
	 */
	@Override
	public ValidatorsResult Result() {
		return validatorsResult.setSuccess(false).setMessage(aNull.message()).setField(field.getName());
	}

	/**
	 * 分组
	 *
	 * @return
	 */
	@Override
	public String group(){
		return aNull.groups();
	}

	/**
	 * 是否执行下一轮校验
	 *
	 * @return
	 */
	@Override
	public boolean next() {
		return aNull.next();
	}
}
